$(function() {
	var linum = $('.mainlist li').length; //图片数量
	var w = linum * 145; //没有间距时ul宽度
	var margin_right = 20; //距离右边的宽度
	var all_length = w + margin_right * linum; //动态计算ul宽度
	$(".piclist").css("width", all_length + "px"); //给所有的ul赋值宽度
	$('.swaplist').html($('.mainlist').html()); //复制内容
	$('.swaplist').css('left', all_length + "px"); //后面ul的定位
	var time = setInterval(run, 1000); //定时器
	var m = 165; //每次移动的距离

	//轮播图的运行
	function run() {
		ml = parseInt($('.mainlist').css('left'));
		sl = parseInt($('.swaplist').css('left'));
		//当ul完全移出屏幕时,转移到后面
		if(ml <= (-all_length)) {
			$('.mainlist').css('left', all_length + "px");
			ml = all_length;
		}
		if(sl <= (-all_length)) {
			$('.swaplist').css('left', all_length + "px");
			sl = all_length;
		}
		//动态计算每次移动后的left值
		ml = ml - m;
		sl = sl - m;
		$('.mainlist').animate({ left: ml + 'px' }, 'slow');
		$('.swaplist').animate({ left: sl + 'px' }, 'slow');
	};
	$(".picbox").on("mouseover", function() {
		clearInterval(time);
	});
	$(".picbox").on("mouseout", function() {
		time = setInterval(run, 1000); 
	});
})